
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  css: {
    loaderOptions: {
      scss: {
        // 全局的scss 配置
        // eslint-disable-next-line quotes
        prependData: `@import "~@/assets/scss/index.scss";`
      },
      postcss: {
        plugins: [
          require('autoprefixer'),
          require('postcss-px2rem')({
            remUnit: 200
          })
        ]
      }
    }
  },
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:7001'
      }
    }
  },
  configureWebpack: {
    externals: {
      AMap: 'AMap',
      AMapUI: 'AMapUI'
    }
  },
  chainWebpack: config => {
    // GraphQL Loader
    config.module.rules.delete('svg')

    config.module
      .rule('svg-icon')
      .test(/\.svg$/)
      .include
      .add(resolve('src/assets/icon'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: '[name]'
      })
  }
}
